#include "ZT_MP3.h"

ZT_MP3::ZT_MP3() 
{
	
}
ZT_MP3::~ZT_MP3() 
{
	
}
void ZT_MP3::begin(SoftwareSerial *serial, int rx, int tx){
  rpin = rx;
  tpin = tx;
  _serialS = serial;
  _serialS->begin(9600);
}

void ZT_MP3::write(uint8_t data[], uint16_t len)
{
    if(_serialS){
        _serialS->write(data, len);
    }else{
    }
}

void ZT_MP3::mp3_volume(uint8_t level){

	uint8_t sum = level + 0xBE;

	uint8_t volume[5] = {0xAA,0x13,0x01,level,sum};

	write(volume,5);

}

void ZT_MP3::mp3_play_chapter(uint16_t chapter){

	uint8_t chapter_h = chapter>>8;

	uint8_t chapter_l = chapter;

	uint8_t sum = 0xB3 + chapter_h + chapter_l;

	uint8_t play_chapter[6] = {0xAA,0x07,0x02,chapter_h,chapter_l,sum};

	write(play_chapter,6);

}

void ZT_MP3::mp3_play(){

	unsigned char play[4] = {0xAA,0x02,0x00,0xAC};

	write(play,4);

}

void ZT_MP3::mp3_next_song(){

	unsigned char play[4] = {0xAA,0x06,0x00,0xB0};

	write(play,4);

}

void ZT_MP3::mp3_last_song(){

	unsigned char play[4] = {0xAA,0x05,0x00,0xAF};

	write(play,4);

}

void ZT_MP3::mp3_vol_up(){

	unsigned char play[4] = {0xAA,0x14,0x00,0xBE};

	write(play,4);

}

void ZT_MP3::mp3_vol_dn(){

	unsigned char play[4] = {0xAA,0x15,0x00,0xBF};

	write(play,4);

}

void ZT_MP3::mp3_stop(){

	unsigned char play[4] = {0xAA,0x04,0x00,0xAE};

	write(play,4);

}

void ZT_MP3::mp3_pause(){

	unsigned char play[4] = {0xAA,0x03,0x00,0xAD};

	write(play,4);

}

void ZT_MP3::mp3_loop_play(){

	unsigned char volume[5] = {0xAA,0x18,0x01,0x00,0xC3};

	write(volume,5);

}
void ZT_MP3::mp3_loop_single_play(){

	unsigned char volume[5] = {0xAA,0x18,0x01,0x01,0xC4};

	write(volume,5);

}
void ZT_MP3::mp3_single_stop(){

	unsigned char volume[5] = {0xAA,0x18,0x01,0x05,0xC5};

	write(volume,5);

}
void ZT_MP3::mp3_random_play(){

	unsigned char volume[5] = {0xAA,0x18,0x01,0x03,0xC6};

	write(volume,5);

}
void ZT_MP3::mp3_order_play(){

	unsigned char volume[5] = {0xAA,0x18,0x01,0x07,0xCA};

	write(volume,5);

}

